<?php
namespace app\serveraddress\service\address;
use \app\manage\service\ApiBase;
use \think\Validate;

class ApiAddress extends ApiBase
{
    protected $addFields = ["pid"=>0, "name"=>"", "py_name"=>"", "zipcode"=>"", "type"=>3, "special"=>0, "order"=>""];
    protected $addressValidate = 'app\serveraddress\validate\Address';
    protected $addressLogic    = '\app\serveraddress\logic\Address';

    // 添加新地区
    public function createAddress()
    {
        if (empty($this->arrData)) {
            return null_data($this->arrData,"参数不能为空！");
        }
        $data = $this->receiveData($this->addFields);
        return $this->stepRun($data,'createAddress','add',$this->addressValidate,$this->addressLogic);
    }

    // 编辑地区信息
    public function editAddress(): array
    {
        if (empty($this->arrData)) {
            return null_data($this->arrData,"参数不能为空！");
        }
        $default = array_merge($this->addFields,['id'=>0]);
        $data = $this->issetReceiveData($default);
        return $this->stepRun($data,'editAddress','edit',$this->addressValidate,$this->addressLogic);
    }

    // 全部地区列表获取
    public function addressList()
    {
        return $this->logic($this->addressLogic)->addressList();
    }

    // 某一类地区列表获取
    public function someAddressList()
    {
        if (empty($this->arrData)) {
            return null_data($this->arrData,"参数不能为空！");
        }
        $data = $this->receiveData(['pid'=>'']);
        return $this->stepRun($data,'someAddressList','pid',$this->addressValidate,$this->addressLogic);
    }
}